package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.UserLikesExpert;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.UserLikesExpertService;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 userLikesExpertController
//@RequestMapping("/userLikesExpertController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /userLikesExpertController
public class UserLikesExpertController {
	@Resource
	UserLikesExpertService userLikesExpertService;

	@GetMapping("/getAlluserLikesExpert")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<UserLikesExpert> getAllUserLikesExpert() throws Exception{
    	System.out.println("查询全部用户点赞专家");
    	return userLikesExpertService.getAllUserLikesExperts();
    }

	@PostMapping("/adduserLikesExpert")
	@ResponseBody
	public DTO<UserLikesExpert> addUserLikesExpert(@RequestBody UserLikesExpert userLikesExpert) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加用户点赞专家成功");
		return userLikesExpertService.addUserLikesExpert(userLikesExpert);
	}
	@DeleteMapping("/deleteuserLikesExpert/{ulikeexpertno}")
	@ResponseBody
    public DTO<UserLikesExpert> deleteUserLikesExpertByUlikeexpertno(@RequestBody @PathVariable("ulikeexpertno") String ulikeexpertno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(ulikeexpertno+"删除用户点赞专家成功");
    	return userLikesExpertService.deleteUserLikesExpertByUlikeexpertno(ulikeexpertno);
    }

	@GetMapping("/userLikesExpertBy/{ulikeexpertno}")
	@ResponseBody
	public DTO<UserLikesExpert> getUserLikesExpertByUlikeexpertno(@PathVariable("ulikeexpertno") String ulikeexpertno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println(ulikeexpertno+"根据主键查询用户点赞专家成功");
		return userLikesExpertService.getUserLikesExpertByUlikeexpertno(ulikeexpertno);
	}

	@PatchMapping("/updateuserLikesExpert")
	@ResponseBody
	public DTO<UserLikesExpert> updateUserLikesExpertByUlikeexpertno(@RequestBody UserLikesExpert userLikesExpert) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改用户点赞专家成功");
		System.out.println(userLikesExpert);
		return userLikesExpertService.updateUserLikesExpertByUlikeexpertno(userLikesExpert);
	}

	@RequestMapping("/userLikesExpert/pageInfo")
	@ResponseBody
	public DTO<UserLikesExpert> getUserLikesExpertByPage(@SpringQueryMap PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询分页");
		return userLikesExpertService.getUserLikesExpertByPage(pageInfo);
	}

}
